package com.jeect.userservice2.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;

import javax.servlet.http.HttpServletRequest;

@RestController
public class UserController {
    @Autowired
    private HttpServletRequest request;
    @GetMapping("/user/{userid}")
    public String setSession(@PathVariable String userid){
        request.getSession().setAttribute("id",userid);
        System.out.println("已经设置session  id="+userid);

        return "已经设置session  id="+userid;
    }

    @GetMapping("/user/currentuser/")
    public String currentuser(){
        String userid = (String)request.getSession().getAttribute("id");
        System.out.println("已经获取session  id="+userid);

        return "id="+userid;
    }
}
